var app = getApp();
Page({
    data: {
        url: "",
        b_id:"",
        imglist: [],
        types:'',
        reason:''
    },
    onLoad: function(a) {
         var f = this,b_id=a.b_id;
         var e = app.siteInfo.uniacid;
                f.setData({
                     uniacid: e,
                     b_id:b_id
                }), app.util.request({
                    url: "entry/wxapp/url",
                    success: function(a) {
                        f.setData({
                            url: a.data
                        });
                    }
                });
                f.getImageList();
    },
    getImageList:function(){
        var self = this;
        app.util.request({
            url: "entry/wxapp/Upreview_show",
            data: {
                openid: wx.getStorageSync("openid"),
                b_id: self.data.b_id
            },
            success: function(a) {
                if(a.data.data.imagelist.length >= 1){
                   self.setData({
                    imglist:a.data.data.imagelist,
                    types:'update',
                    reason:a.data.data.reason 
                  }) 
                }
            }
        });
    },
     //图片点击事件
 imgYu:function(event){
 var src = event.currentTarget.dataset.src;//获取data-src
 var imgList = event.currentTarget.dataset.list;//获取data-list
 //图片预览
 wx.previewImage({
  current: src, // 当前显示图片的http链接
  urls: imgList // 需要预览的图片http链接列表
 })
 },
    delPic: function(a) {
        var e = this, i = a.currentTarget.dataset.index;
        wx.showModal({
            title: "提示",
            content: "是否删除该图片",
            success: function(a) {
                if (a.confirm) {
                    var t = e.data.imglist;
                    t.splice(i, 1), e.setData({
                        imglist: t
                    });
                }
            }
        });
    },
    choosePhoto: function() {
        var e = this;
        wx.chooseImage({
            count: 9 - e.data.imglist.length,
            sizeType: [ "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(a) {
                a.tempFilePaths;
                var t = a.tempFilePaths.length;
                e.uploadDIY(a.tempFilePaths, 0, 0, 0, t), console.log(e.data.imglist);
            }
        });
    },
    uploadDIY: function(a, t, e, i, s) {
        var o = this, n = this, h = n.data.uniacid, u = n.data.imglist;
        wx.uploadFile({
            url: n.data.url + "app/index.php?i=" + h + "&c=entry&a=wxapp&do=upload&m=hyb_jianzhi",
            filePath: a[i],
            name: "upfile",
            formData: {
                openid: wx.getStorageSync("openid")
            },
            success: function(a) {
                console.log(a.data), console.log(u), t++, u.push(a.data), n.setData({
                    imglist: u
                });
            },
            fail: function(a) {
                e++;
            },
            complete: function() {
                ++i == s ? (wx.hideLoading(), console.log("总共" + t + "张上传成功," + e + "张上传失败！")) : o.uploadDIY(a, t, e, i, s);
            }
        });
    },
    // 上传作品按钮
    hdlupReview:function(n){
        var self = this;
        app.util.request({
            url: "entry/wxapp/upreview",
            data: {
                openid: wx.getStorageSync("openid"),
                b_id: self.data.b_id,
                imagelist:self.data.imglist
            },
            success: function(a) {
                wx.showToast({
                    title: "上传成功!"
                   }), setTimeout(function() {
                       wx.navigateTo({
                            url: "/hyb_jianzhi/index/index"
                        });
                 }, 1e3);
            }
        });
    },
    hdlupDateReview:function(n){
        var self = this;
        app.util.request({
            url: "entry/wxapp/Upreview_update",
            data: {
                openid: wx.getStorageSync("openid"),
                b_id: self.data.b_id,
                imagelist:self.data.imglist
            },
            success: function(a) {
                wx.showToast({
                    title: "修改成功!"
                   }), setTimeout(function() {
                       wx.navigateTo({
                            url: "/hyb_jianzhi/index/index"
                        });
                 }, 1e3);
            }
        });
    },
    remove: function(a) {},
    onReady: function() {},
    submitformid: function(a) {
        console.log(a.detail.formId), this.getform(a.detail.formId);
    },
    getform: function(a) {
        console.log(a), app.util.request({
            url: "entry/wxapp/Formid",
            data: {
                openid: wx.getStorageSync("openid"),
                formid: a
            },
            success: function(a) {}
        });
    },
    
    onShow: function() {
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});